var queryVm = new Vue({
	el: '#query-data-content',
	data: function() {
		return{
			type: '固定资产',
			typeid: 'equipment',
			equipmentState: '',
			depart: '部门',
			departid: '',
			workshop: '车间',
			workshopid: '',
			listData: [],
		}
	},
	mounted: function() {
		var self = this;
		mui.init();
		mui.plusReady(function () {
			self.initLayout();
		    self.initDepartData();
			self.initWorkshopData();
			self.getQueryData();
		})
	},
	methods:{
		initLayout:function() {
			mui('.mui-scroll-wrapper').scroll({
				scrollY: true, //是否竖向滚动
				scrollX: false, //是否横向滚动
				startX: 0, //初始化时滚动至x
				startY: 0, //初始化时滚动至y
				indicators: true, //是否显示滚动条
				deceleration: 0.0006, //阻尼系数,系数越小滑动越灵敏
				bounce: true //是否启用回弹
			})
		},
		initDepartData: function() {
			var self = this;
			this.departPicker = new mui.PopPicker();
			var url = config.requestBaseUrl + 'getSystemStandData';
			mui.ajax(url,{
			 	data:{
					type: 'depart'
			 	},
			 	dataType:'json',//服务器返回json格式数据
			 	type:'get',//HTTP请求类型
			 	timeout:3000,//超时时间设置为10秒；
			 	success:function(data){
					var departData = [];
					data.data.forEach(function(item, index) {
						departData.push({value: item.id, text: item.name})
					})
					self.departPicker.setData(departData);
			 	},
			 	error:function(xhr,type,errorThrown){
					mui.alert("出错了:" + errorThrown);
			 	}
			});
		},
		initWorkshopData: function() {
			var self = this;
			this.workshopPicker = new mui.PopPicker();
			var url = config.requestBaseUrl + 'getSystemStandData';
			mui.ajax(url,{
			 	data:{
					type:'workshop'
			 	},
			 	dataType:'json',//服务器返回json格式数据
			 	type:'get',//HTTP请求类型
			 	timeout:3000,//超时时间设置为10秒；
			 	success:function(data){
					self.workshopSourceData = data.data;
			 	},
			 	error:function(xhr,type,errorThrown){
					console.log("出错了:" + errorThrown);
					mui.alert("出错了:" + errorThrown);
			 	}
			});
		},
		toTypePicker: function() {
			var self = this;
			this.typePicker = new mui.PopPicker();
			this.typePicker.setData([{text: '固定资产', value: 'equipment'}, {text: '事件', value: 'event'}, {text: '需求', value: 'demand'}]);
			this.typePicker.show(function (selectItems) {
				self.depart = "部门";
				self.departid = "";
				self.workshop = "车间";
				self.workshopid = "";
				
				self.type = selectItems[0].text;
				self.typeid = selectItems[0].value;
				setTimeout(function() {
					self.getQueryData();
				}, 0);
			})
		},
		toDepartPicker: function() {
			var self = this;
			this.departPicker.show(function (selectItems) {
				self.workshop = '车间';
				self.workshopid = '';
				
				self.depart = selectItems[0].text;
				self.departid = selectItems[0].value;
				setTimeout(function() {
					console.log("这里")
					self.workshopDataConst();
					self.getQueryData();
				}, 0);
			})
		},
		toWorkshopPicker: function() {
			var self = this;
			console.log(this.depart)
			if(!this.depart || this.depart == "部门") {
				mui.toast("请先选择部门!");
			} else {
				this.workshopPicker.show(function (selectItems) {
					self.workshop = selectItems[0].text;
					self.workshopid = selectItems[0].value;
					setTimeout(function() {
						self.getQueryData();
					}, 0);
				})
			}
		},
		workshopDataConst: function() {
			var self = this;
			var workshopData = [];
			this.workshopSourceData.forEach(function(item, index) {
				if(item.id == self.departid) {
					workshopData.push({value: item.id, text: item.name});
					
				}
			})
			
			this.workshopPicker.setData(workshopData);
		},
		getQueryData: function() {
			var self = this;
			var url = config.requestBaseUrl + "queryData"
			mui.ajax(url,{
				data:{
					type: this.typeid,
					departid: this.departid,
					workshopid: this.workshopid
				},
				dataType:'json',//服务器返回json格式数据
				type:'get',//HTTP请求类型
				timeout:10000,//超时时间设置为10秒；
				success:function(data){
					mui.toast(data.msg);
					if(data.isSuccess) {
						self.listData = data.data;
					}
				},
				error:function(xhr,type,errorThrown){
					// console.log("失败:" + errorThrown);
					mui.toast("失败:" + errorThrown)
				}
			});
		},
		toEquipment: function(item) {
			var equipManagePage = plus.webview.getWebviewById('equipManage');
			if(!equipManagePage) {
				equipManagePage = plus.webview.create(
				'equipmentManage.html', 
				'equipManage', 
				{left: '0%'},
				{
					code: item.zcbh,
					type: "CODE93"
				});
			}
			equipManagePage.show(
			{extras: {
					code: item.zcbh,
					type: "CODE93"
				},
			});
		},
		toEvent: function(item) {
			
		},
		toDemand: function(item) {
			
		}
	}
})